home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacOS 8 Resources / Developer Tools / Mac OS 8 Interfaces & Libraries / Interfaces / CIncludes / DBDMA.h < prev    next >
C/C++ Source or Header  |  1996-05-01  |  12KB  |  356 lines

  1. /*
  2.      File:        DBDMA.h
  3.  
  4.      Contains:    Descriptor Based DMA Interfaces
  5.  
  6.      Version:    Technology:    System 7.5
  7.                  Release:    Universal Interfaces 3.0d3 on Copland DR1
  8.  
  9.      Copyright:    © 1984-1996 by Apple Computer, Inc.  All rights reserved.
  10.  
  11.      Bugs?:        If you find a problem with this file, send the file and version
  12.                  information (from above) and the problem description to:
  13.  
  14.                      Internet:    apple.bugs@applelink.apple.com
  15.                      AppleLink:    APPLE.BUGS
  16.  
  17. */
  18. #ifndef __DBDMA__
  19. #define __DBDMA__
  20.  
  21. #ifndef __CONDITIONALMACROS__
  22. #include <ConditionalMacros.h>
  23. #endif
  24. #ifndef __PCI__
  25. #include <PCI.h>
  26. #endif
  27. #if FOR_SYSTEM8_PREEMPTIVE
  28. #ifndef __CODEFRAGMENTS__
  29. #include <CodeFragments.h>
  30. #endif
  31. #ifndef __DRIVERSERVICES__
  32. #include <DriverServices.h>
  33. #endif
  34. #endif
  35.  
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39.  
  40. #if PRAGMA_IMPORT_SUPPORTED
  41. #pragma import on
  42. #endif
  43.  
  44. #if PRAGMA_ALIGN_SUPPORTED
  45. #pragma options align=mac68k
  46. #endif
  47.  
  48. #if FOR_SYSTEM7_AND_SYSTEM8_PREEMPTIVE
  49. /* This structure defines the standard set of DB-DMA channel registers.*/
  50. struct DBDMAChannelRegisters {
  51.     unsigned long                     channelControl;
  52.     unsigned long                     channelStatus;
  53.     unsigned long                     commandPtrHi;                /* implementation optional*/
  54.     unsigned long                     commandPtrLo;
  55.     unsigned long                     interruptSelect;            /* implementation optional*/
  56.     unsigned long                     branchSelect;                /* implementation optional*/
  57.     unsigned long                     waitSelect;                    /* implementation optional*/
  58.     unsigned long                     transferModes;                /* implementation optional*/
  59.     unsigned long                     data2PtrHi;                    /* implementation optional*/
  60.     unsigned long                     data2PtrLo;                    /* implementation optional*/
  61.  
  62.     unsigned long                     reserved1;
  63.     unsigned long                     addressHi;                    /* implementation optional*/
  64.     unsigned long                     reserved2[4];
  65.     unsigned long                     unimplemented[16];
  66.  
  67.                                                                 /* This structure must remain fully padded to 256 bytes.*/
  68.     unsigned long                     undefined[32];
  69. };
  70. typedef struct DBDMAChannelRegisters DBDMAChannelRegisters;
  71.  
  72. /* These constants define the DB-DMA channel control words and status flags.*/
  73.  
  74. enum {
  75.     kdbdmaSetRun                = 0x80008000,
  76.     kdbdmaClrRun                = 0x80000000,
  77.     kdbdmaSetPause                = 0x40004000,
  78.     kdbdmaClrPause                = 0x40000000,
  79.     kdbdmaSetFlush                = 0x20002000,
  80.     kdbdmaSetWake                = 0x10001000,
  81.     kdbdmaClrDead                = 0x08000000,
  82.     kdbdmaSetS7                    = 0x00800080,
  83.     kdbdmaClrS7                    = 0x00800000,
  84.     kdbdmaSetS6                    = 0x00400040,
  85.     kdbdmaClrS6                    = 0x00400000,
  86.     kdbdmaSetS5                    = 0x00200020,
  87.     kdbdmaClrS5                    = 0x00200000,
  88.     kdbdmaSetS4                    = 0x00100010,
  89.     kdbdmaClrS4                    = 0x00100000,
  90.     kdbdmaSetS3                    = 0x00080008,
  91.     kdbdmaClrS3                    = 0x00080000,
  92.     kdbdmaSetS2                    = 0x00040004,
  93.     kdbdmaClrS2                    = 0x00040000,
  94.     kdbdmaSetS1                    = 0x00020002,
  95.     kdbdmaClrS1                    = 0x00020000,
  96.     kdbdmaSetS0                    = 0x00010001,
  97.     kdbdmaClrS0                    = 0x00010000,
  98.     kdbdmaClrAll                = 0xFFFF0000
  99. };
  100.  
  101.  
  102. enum {
  103.     kdbdmaRun                    = 0x00008000,
  104.     kdbdmaPause                    = 0x00004000,
  105.     kdbdmaFlush                    = 0x00002000,
  106.     kdbdmaWake                    = 0x00001000,
  107.     kdbdmaDead                    = 0x00000800,
  108.     kdbdmaActive                = 0x00000400,
  109.     kdbdmaBt                    = 0x00000100,
  110.     kdbdmaS7                    = 0x00000080,
  111.     kdbdmaS6                    = 0x00000040,
  112.     kdbdmaS5                    = 0x00000020,
  113.     kdbdmaS4                    = 0x00000010,
  114.     kdbdmaS3                    = 0x00000008,
  115.     kdbdmaS2                    = 0x00000004,
  116.     kdbdmaS1                    = 0x00000002,
  117.     kdbdmaS0                    = 0x00000001
  118. };
  119.  
  120. /*
  121.  This structure defines the DB-DMA channel command descriptor.
  122.  *** WARNING:    Endian-ness issues must be considered when performing load/store! ***
  123.  ***            DB-DMA specifies memory organization as quadlets so it is not correct
  124.  ***            to think of either the operation or result field as two 16-bit fields.
  125.  ***            This would have undesirable effects on the byte ordering within their
  126.  ***            respective quadlets. Use the accessor macros provided below.
  127. */
  128. struct DBDMADescriptor {
  129.     unsigned long                     operation;                    /* cmd || key || i || b || w || reqCount*/
  130.     unsigned long                     address;
  131.     unsigned long                     cmdDep;
  132.     unsigned long                     result;                        /* xferStatus || resCount*/
  133. };
  134. typedef struct DBDMADescriptor DBDMADescriptor;
  135.  
  136. typedef DBDMADescriptor *DBDMADescriptorPtr;
  137. /* These constants define the DB-DMA channel command operations and modifiers.*/
  138.  
  139. enum {
  140.                                                                 /* Command.cmd operations*/
  141.     OUTPUT_MORE                    = 0x00000000,
  142.     OUTPUT_LAST                    = 0x10000000,
  143.     INPUT_MORE                    = 0x20000000,
  144.     INPUT_LAST                    = 0x30000000,
  145.     STORE_QUAD                    = 0x40000000,
  146.     LOAD_QUAD                    = 0x50000000,
  147.     NOP_CMD                        = 0x60000000,
  148.     STOP_CMD                    = 0x70000000,
  149.     kdbdmaCmdMask                = 0xF0000000
  150. };
  151.  
  152.  
  153. enum {
  154.                                                                 /* Command.key modifiers (choose one for INPUT, OUTPUT, LOAD, and STORE)*/
  155.     KEY_STREAM0                    = 0x00000000,                    /* default modifier*/
  156.     KEY_STREAM1                    = 0x01000000,
  157.     KEY_STREAM2                    = 0x02000000,
  158.     KEY_STREAM3                    = 0x03000000,
  159.     KEY_REGS                    = 0x05000000,
  160.     KEY_SYSTEM                    = 0x06000000,
  161.     KEY_DEVICE                    = 0x07000000,
  162.     kdbdmaKeyMask                = 0x07000000,                    /* Command.i modifiers (choose one for INPUT, OUTPUT, LOAD, STORE, and NOP)*/
  163.     kIntNever                    = 0x00000000,                    /* default modifier*/
  164.     kIntIfTrue                    = 0x00100000,
  165.     kIntIfFalse                    = 0x00200000,
  166.     kIntAlways                    = 0x00300000,
  167.     kdbdmaIMask                    = 0x00300000,                    /* Command.b modifiers (choose one for INPUT, OUTPUT, and NOP)*/
  168.     kBranchNever                = 0x00000000,                    /* default modifier*/
  169.     kBranchIfTrue                = 0x00040000,
  170.     kBranchIfFalse                = 0x00080000,
  171.     kBranchAlways                = 0x000C0000,
  172.     kdbdmaBMask                    = 0x000C0000,                    /* Command.w modifiers (choose one for INPUT, OUTPUT, LOAD, STORE, and NOP)*/
  173.     kWaitNever                    = 0x00000000,                    /* default modifier*/
  174.     kWaitIfTrue                    = 0x00010000,
  175.     kWaitIfFalse                = 0x00020000,
  176.     kWaitAlways                    = 0x00030000,
  177.     kdbdmaWMask                    = 0x00030000,                    /* operation masks*/
  178.     kdbdmaCommandMask            = 0xFFFF0000,
  179.     kdbdmaReqCountMask            = 0x0000FFFF
  180. };
  181.  
  182. /* These constants define the DB-DMA channel command results.*/
  183.  
  184. enum {
  185.     kXferStatusRun                = kdbdmaRun << 16,
  186.     kXferStatusPause            = kdbdmaPause << 16,
  187.     kXferStatusFlush            = kdbdmaFlush << 16,
  188.     kXferStatusWake                = kdbdmaWake << 16,
  189.     kXferStatusDead                = kdbdmaDead << 16,
  190.     kXferStatusActive            = kdbdmaActive << 16,
  191.     kXferStatusBt                = kdbdmaBt << 16,
  192.     kXferStatusS7                = kdbdmaS7 << 16,
  193.     kXferStatusS6                = kdbdmaS6 << 16,
  194.     kXferStatusS5                = kdbdmaS5 << 16,
  195.     kXferStatusS4                = kdbdmaS4 << 16,
  196.     kXferStatusS3                = kdbdmaS3 << 16,
  197.     kXferStatusS2                = kdbdmaS2 << 16,
  198.     kXferStatusS1                = kdbdmaS1 << 16,
  199.     kXferStatusS0                = kdbdmaS0 << 16,                /* result masks*/
  200.     kdbdmaResCountMask            = 0x0000FFFF,
  201.     kdbdmaXferStatusMask        = kdbdmaResCountMask << 16
  202. };
  203.  
  204. #if FOR_SYSTEM8_PREEMPTIVE
  205. typedef void *DBDMAChannelConnectionPtr;
  206. /*
  207. /////////////////////////////////////////////////////////////////////////////////
  208.  Channel Connections
  209. */
  210. extern OSStatus OpenDBDMAChannel(DBDMAChannelRegisters *DBDMAPtr, DBDMAChannelConnectionPtr *channelConnection, UInt32 cclNum, LogicalAddress *logicalAddr, PhysicalAddress *physicalAddr);
  211.  
  212. extern void CloseDBDMAChannel(DBDMAChannelConnectionPtr channelConnection);
  213.  
  214. /*
  215. /////////////////////////////////////////////////////////////////////////////////
  216.  Client Buffer Assignment
  217. */
  218. extern void SetDBDMAPhysicalAddress(DBDMAChannelConnectionPtr channelConnection, Boolean isReadTransfer, PhysicalAddress addressPtr, ByteCount transferCount);
  219.  
  220. /*
  221. /////////////////////////////////////////////////////////////////////////////////
  222.  Channel Control Operations
  223. */
  224. extern void StartDBDMA(DBDMAChannelConnectionPtr channelConnection);
  225.  
  226. extern void StopDBDMA(DBDMAChannelConnectionPtr channelConnection);
  227.  
  228. extern void ResetDBDMA(DBDMAChannelConnectionPtr channelConnection);
  229.  
  230. extern void PrepDBDMA(DBDMAChannelConnectionPtr channelConnection);
  231.  
  232. #endif
  233. #if FOR_SYSTEM8_PREEMPTIVE
  234.     #define NOP() SynchronizeIO()
  235.     #define SYNC() SynchronizeIO()
  236. #endif
  237.  
  238. /*  These macros are are DBDMAChannelRegisters accessor functions. */
  239.  
  240. /*     void SetChannelControl (DBDMAChannelRegisters *registerSetPtr, unsigned long ctlValue); */
  241. #define SetChannelControl(registerSetPtr,ctlValue)                                                \
  242.     (NOP(), (registerSetPtr)->channelControl = EndianSwap32Bit(ctlValue), NOP())
  243.  
  244.  
  245. /*     unsigned long GetChannelStatus (DBDMAChannelRegisters *registerSetPtr); */
  246. #define GetChannelStatus(registerSetPtr)                                                        \
  247.     (EndianSwap32Bit((registerSetPtr)->channelStatus))
  248.  
  249.  
  250. /*     unsigned long GetCommandPtr (DBDMAChannelRegisters *registerSetPtr); */
  251. #define GetCommandPtr(registerSetPtr)                                                            \
  252.     (EndianSwap32Bit((registerSetPtr)->commandPtrLo))
  253.  
  254. /*     void SetCommandPtr (DBDMAChannelRegisters *registerSetPtr, unsigned long cclPtr); */
  255. #define SetCommandPtr(registerSetPtr,cclPtr)                                                    \
  256.     ((registerSetPtr)->commandPtrLo = EndianSwap32Bit(cclPtr), NOP())
  257.  
  258.  
  259. /*     unsigned long GetInterruptSelect (DBDMAChannelRegisters *registerSetPtr); */
  260. #define GetInterruptSelect(registerSetPtr)                                                        \
  261.     (EndianSwap32Bit((registerSetPtr)->interruptSelect))
  262.  
  263. /*     void SetInterruptSelect (DBDMAChannelRegisters *registerSetPtr, unsigned long intSelValue); */
  264. #define SetInterruptSelect(registerSetPtr,intSelValue)                                            \
  265.     ((registerSetPtr)->interruptSelect = EndianSwap32Bit(intSelValue), NOP())
  266.  
  267.  
  268. /*     unsigned long GetBranchSelect (DBDMAChannelRegisters *registerSetPtr); */
  269. #define GetBranchSelect(registerSetPtr)                                                            \
  270.     (EndianSwap32Bit((registerSetPtr)->branchSelect))
  271.  
  272. /*     void SetBranchSelect (DBDMAChannelRegisters *registerSetPtr, unsigned long braSelValue); */
  273. #define SetBranchSelect(registerSetPtr,braSelValue)                                                \
  274.     ((registerSetPtr)->branchSelect = EndianSwap32Bit(braSelValue), NOP())
  275.  
  276.  
  277. /*     unsigned long GetWaitSelect (DBDMAChannelRegisters *registerSetPtr); */
  278. #define GetWaitSelect(registerSetPtr)                                                            \
  279.     (EndianSwap32Bit((registerSetPtr)->waitSelect))
  280.  
  281. /*     void SetWaitSelect (DBDMAChannelRegisters *registerSetPtr, unsigned long waitSelValue); */
  282. #define SetWaitSelect(registerSetPtr,waitSelValue)                                                \
  283.     ((registerSetPtr)->waitSelect = EndianSwap32Bit(waitSelValue), NOP())
  284.  
  285. /*  These macros are DBDMADescriptor accessor functions. */
  286.  
  287. /*     void MakeCCDescriptor (DBDMADescriptor *descPtr, */
  288. /*         unsigned long op, unsigned long addr); */
  289. #define MakeCCDescriptor(descPtr,op,addr)                                                        \
  290.     ((descPtr)->address = EndianSwap32Bit(addr),                                                \
  291.     (descPtr)->cmdDep = 0,                                                                        \
  292.     (descPtr)->result = 0,                                                                        \
  293.     SYNC(),                                                                                        \
  294.     (descPtr)->operation = EndianSwap32Bit(op),                                                    \
  295.     SYNC())
  296.  
  297. /*     void MakeCmdDepCCDescriptor (DBDMADescriptor *descPtr, */
  298. /*         unsigned long op, unsigned long addr, unsigned long dep); */
  299. #define MakeCmdDepCCDescriptor(descPtr,op,addr,dep)                                                \
  300.     ((descPtr)->address = EndianSwap32Bit(addr),                                                \
  301.     (descPtr)->cmdDep = EndianSwap32Bit(dep),                                                    \
  302.     (descPtr)->result = 0,                                                                        \
  303.     SYNC(),                                                                                        \
  304.     (descPtr)->operation = EndianSwap32Bit(op),                                                    \
  305.     SYNC())
  306.  
  307. /*     unsigned long GetCCOperation (DBDMADescriptor *descPtr) */
  308. #define GetCCOperation(descPtr)                                                                    \
  309.     (EndianSwap32Bit((descPtr)->operation))
  310.  
  311. /*     void SetCCOperation (DBDMADescriptor *descPtr, unsigned long operationValue) */
  312. #define SetCCOperation(descPtr,operationValue)                                                    \
  313.     ((descPtr)->operation = EndianSwap32Bit(operationValue))
  314.  
  315.  
  316. /*     unsigned long GetCCAddress (DBDMADescriptor *descPtr) */
  317. #define GetCCAddress(descPtr)                                                                    \
  318.     (EndianSwap32Bit((descPtr)->address))
  319.  
  320. /*     void SetCCAddress (DBDMADescriptor *descPtr, unsigned long addressValue) */
  321. #define SetCCAddress(descPtr,addressValue)                                                        \
  322.     ((descPtr)->address = EndianSwap32Bit(addressValue))
  323.  
  324.  
  325. /*     unsigned long GetCCCmdDep (DBDMADescriptor *descPtr) */
  326. #define GetCCCmdDep(descPtr)                                                                    \
  327.     (EndianSwap32Bit((descPtr)->cmdDep))
  328.  
  329. /*     void SetCCCmdDep (DBDMADescriptor *descPtr, unsigned long cmdDepValue) */
  330. #define SetCCCmdDep(descPtr,cmdDepValue)                                                        \
  331.     ((descPtr)->cmdDep = EndianSwap32Bit(cmdDepValue))
  332.  
  333. /*     unsigned long GetCCResult (DBDMADescriptor *descPtr) */
  334. #define GetCCResult(descPtr)                                                                    \
  335.     (EndianSwap32Bit((descPtr)->result))
  336.  
  337. /*     void SetCCResult (DBDMADescriptor *descPtr, unsigned long resultValue) */
  338. #define SetCCResult(descPtr,resultValue)                                                        \
  339.     ((descPtr)->result = EndianSwap32Bit(resultValue))
  340. #endif
  341.  
  342. #if PRAGMA_ALIGN_SUPPORTED
  343. #pragma options align=reset
  344. #endif
  345.  
  346. #if PRAGMA_IMPORT_SUPPORTED
  347. #pragma import off
  348. #endif
  349.  
  350. #ifdef __cplusplus
  351. }
  352. #endif
  353.  
  354. #endif /* __DBDMA__ */
  355.  
  356.